39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
74#define HBRIDGE18_REG_IC_STAT 0x00
75#define HBRIDGE18_REG_OCP_STAT_1 0x01
76#define HBRIDGE18_REG_OLD_STAT_1 0x04
77#define HBRIDGE18_REG_CONFIG_CTRL 0x07
78#define HBRIDGE18_REG_OP_CTRL_1 0x08
79#define HBRIDGE18_REG_PWM_CTRL_1 0x0B
80#define HBRIDGE18_REG_PWM_CTRL_2 0x0C
81#define HBRIDGE18_REG_FW_CTRL_1 0x0D
82#define HBRIDGE18_REG_PWM_MAP_CTRL_1 0x0F
83#define HBRIDGE18_REG_PWM_MAP_CTRL_2 0x10
84#define HBRIDGE18_REG_PWM_FREQ_CTRL_1 0x13
85#define HBRIDGE18_REG_PWM_DUTY_CTRL_1 0x15
86#define HBRIDGE18_REG_PWM_DUTY_CTRL_2 0x16
87#define HBRIDGE18_REG_PWM_DUTY_CTRL_3 0x17
88#define HBRIDGE18_REG_PWM_DUTY_CTRL_4 0x18
89#define HBRIDGE18_REG_SR_CTRL_1 0x1D
90#define HBRIDGE18_REG_OLD_CTRL_1 0x1F
91#define HBRIDGE18_REG_OLD_CTRL_2 0x20
92#define HBRIDGE18_REG_OLD_CTRL_3 0x21
93#define HBRIDGE18_REG_OLD_CTRL_4 0x22
94#define HBRIDGE18_REG_OLD_CTRL_5 0x23
95#define HBRIDGE18_REG_OLD_CTRL_6 0x24
113#define HBRIDGE18_IC_STAT_OTSD 0x40
114#define HBRIDGE18_IC_STAT_OTW 0x20
115#define HBRIDGE18_IC_STAT_OLD 0x10
116#define HBRIDGE18_IC_STAT_OCP 0x08
117#define HBRIDGE18_IC_STAT_UVLO 0x04
118#define HBRIDGE18_IC_STAT_OVP 0x02
119#define HBRIDGE18_IC_STAT_NPOR 0x01
125#define HBRIDGE18_CONFIG_CTRL_POLD_EN 0x80
126#define HBRIDGE18_CONFIG_CTRL_IC_ID_DRV8904 0x40
127#define HBRIDGE18_CONFIG_CTRL_IC_ID_MASK 0x70
128#define HBRIDGE18_CONFIG_CTRL_OCP_REP 0x08
129#define HBRIDGE18_CONFIG_CTRL_OTW_REP 0x04
130#define HBRIDGE18_CONFIG_CTRL_EXT_OVP 0x02
131#define HBRIDGE18_CONFIG_CTRL_CLR_FLT 0x01
137#define HBRIDGE18_OP_CTRL_1_HB4_HS_EN 0x80
138#define HBRIDGE18_OP_CTRL_1_HB4_LS_EN 0x40
139#define HBRIDGE18_OP_CTRL_1_HB3_HS_EN 0x20
140#define HBRIDGE18_OP_CTRL_1_HB3_LS_EN 0x10
141#define HBRIDGE18_OP_CTRL_1_HB2_HS_EN 0x08
142#define HBRIDGE18_OP_CTRL_1_HB2_LS_EN 0x04
143#define HBRIDGE18_OP_CTRL_1_HB1_HS_EN 0x02
144#define HBRIDGE18_OP_CTRL_1_HB1_LS_EN 0x01
145#define HBRIDGE18_OP_CTRL_1_HB34_MASK 0xF0
146#define HBRIDGE18_OP_CTRL_1_HB12_MASK 0x0F
152#define HBRIDGE18_OLD_CTRL_1_HB4_OLD_DIS 0x08
153#define HBRIDGE18_OLD_CTRL_1_HB3_OLD_DIS 0x04
154#define HBRIDGE18_OLD_CTRL_1_HB2_OLD_DIS 0x02
155#define HBRIDGE18_OLD_CTRL_1_HB1_OLD_DIS 0x01
161#define HBRIDGE18_MOTOR_0 0
162#define HBRIDGE18_MOTOR_1 1
168#define HBRIDGE18_MOTOR_STATE_COAST 0
169#define HBRIDGE18_MOTOR_STATE_FORWARD 1
170#define HBRIDGE18_MOTOR_STATE_REVERSE 2
171#define HBRIDGE18_MOTOR_STATE_BRAKE_LS 3
172#define HBRIDGE18_MOTOR_STATE_BRAKE_HS 4
182#define HBRIDGE18_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
183#define HBRIDGE18_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
201#define HBRIDGE18_MAP_MIKROBUS( cfg, mikrobus ) \
202 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
203 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
204 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
205 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
206 cfg.sleep = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
207 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t hbridge18_check_communication(hbridge18_t *ctx)
H-Bridge 18 check communication function.
void hbridge18_enable_device(hbridge18_t *ctx)
H-Bridge 18 enable device function.
void hbridge18_disable_device(hbridge18_t *ctx)
H-Bridge 18 disable device function.
err_t hbridge18_set_motor_state(hbridge18_t *ctx, uint8_t motor, uint8_t state)
H-Bridge 18 set motor state function.
err_t hbridge18_init(hbridge18_t *ctx, hbridge18_cfg_t *cfg)
H-Bridge 18 initialization function.
err_t hbridge18_write_reg(hbridge18_t *ctx, uint8_t reg, uint8_t data_in)
H-Bridge 18 write register function.
uint8_t hbridge18_get_fault_pin(hbridge18_t *ctx)
H-Bridge 18 get fault pin function.
err_t hbridge18_read_reg(hbridge18_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 18 read register function.
void hbridge18_cfg_setup(hbridge18_cfg_t *cfg)
H-Bridge 18 configuration object setup function.
err_t hbridge18_default_cfg(hbridge18_t *ctx)
H-Bridge 18 default configuration function.
hbridge18_return_value_t
H-Bridge 18 Click return value data.
Definition hbridge18.h:261
@ HBRIDGE18_OK
Definition hbridge18.h:262
@ HBRIDGE18_ERROR
Definition hbridge18.h:263
This file contains SPI specific macros, functions, etc.
H-Bridge 18 Click configuration object.
Definition hbridge18.h:238
pin_name_t sleep
Definition hbridge18.h:246
spi_master_chip_select_polarity_t cs_polarity
Definition hbridge18.h:252
pin_name_t sck
Definition hbridge18.h:242
spi_master_mode_t spi_mode
Definition hbridge18.h:251
pin_name_t mosi
Definition hbridge18.h:241
uint32_t spi_speed
Definition hbridge18.h:250
pin_name_t miso
Definition hbridge18.h:240
pin_name_t cs
Definition hbridge18.h:243
pin_name_t fault
Definition hbridge18.h:247
H-Bridge 18 Click context object.
Definition hbridge18.h:217
digital_out_t sleep
Definition hbridge18.h:219
uint8_t ic_status
Definition hbridge18.h:229
spi_master_t spi
Definition hbridge18.h:225
digital_in_t fault
Definition hbridge18.h:222
pin_name_t chip_select
Definition hbridge18.h:227